<?php
if (!defined("__WD__")) exit("Wrong Connect");

class Kong extends __Kong{
	
	function __construct() {

		parent::__construct();

		$this->load->module( "mysql" , $this->db );
		$this->load->module( "input" , $this->input );
		
		$this->data->title = $this->data->kong_name." - ".$this->data->title;


	}
	function doit( $args ) {
		$stat1 = (isset($args[0]))?$args[0]:"list";
		$stat2 = (isset($args[1]))?$args[1]:"default";
		
		// Action!
		if ($this->input->post_exists("action")) {
			// kong Class.		
			$this->load->kong("proc");
			$this->proc = new Kong_Proc();
			$this->proc->doit();
		}

		switch($stat1) {
			case "list" :
				$this->viewList();break;
			case "new" :
				$this->viewNew();break;
			default :
				$this->viewModify( $stat1 );break;
			
		}

	}
	
	function viewList() {

		$this->load->model("admin/bbs", $this->bbs);

		$board		= $this->db->fetch_assoc("select `id`,`name` from `wd_board`");
		$category	= $this->db->fetch_assoc("select `idx`,`name` from `wd_category`");

		foreach( $board as $v )  $this->data->board[ $v['id'] ] = $v['name'];
		foreach( $category as $v )  $this->data->category[ $v['idx'] ] = $v['name'];
		
		unset($board, $category);

		$pagination = $this->bbs->getPagination("wd_data");

		$this->data->rows		= $pagination["rows"];
		$this->data->pagination = $pagination["html"];
		
		// -- 끝.
		$this->_header();
		$this->load->kong("view/list");
		$this->_footer();
	
	}
	function viewNew() {

		$this->data->category = $this->db->fetch_assoc("select `idx`,`name` from `wd_category` where `board_id`='blog' order by `order` asc;");
		$this->data->redactor = true;

		$this->css("css/new");
		$this->js("js/new");
		
		$this->_header();
		$this->load->kong("view/new");
		$this->_footer();
		
		
	}
	function viewModify( $idx ) {

		$this->data->result	= $this->db->result( "select * from `wd_data` where `idx`=?", array($idx) );
		$this->data->files	= @unserialize( $this->data->result['files'] );
		
		
		$this->data->category = $this->db->fetch_assoc("select `idx`,`name` from `wd_category` where `board_id`='blog' order by `order` asc;");
		$this->data->redactor = true;

		$this->css("css/new");
		$this->js("js/new");
		
		$this->_header();
		$this->load->kong("view/modify");
		$this->_footer();
		
		
	}

	

}